<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
      <el-form-item label="任务Id" prop="taskId">
        <el-input v-model="queryParams.taskId" placeholder="请输入任务ID" clearable style="width: 200px"
          @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="数据来源" prop="dataFrom">
        <el-select filterable style="width: 100%" v-model="queryParams.dataFrom" placeholder="请选择"
          @change="changeSource" clearable>
          <el-option v-for="dict in data_sours" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="关联照片集名称" prop="pictureGroupName">
        <el-input v-model="queryParams.pictureGroupName" placeholder="请输入关联照片集名称" clearable style="width: 200px"
          @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="是否已完成" prop="isComplete">
        <el-select v-model="queryParams.isComplete" placeholder="请选择" clearable style="width: 200px">
          <el-option v-for="dict in CompleteOptions" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="是否告知发起方" prop="isCallBacked">
        <el-select v-model="queryParams.isCallBacked" placeholder="请选择" clearable style="width: 200px">
          <el-option v-for="dict in CompleteOptions" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="上报时间" prop="sbTime">
        <el-date-picker value-format="YYYY-MM-DD" v-model="queryParams.sbTime" type="daterange" range-separator="-"
          start-placeholder="开始时间" end-placeholder="截止时间" :size="size" @change="sbTimeChange" />
      </el-form-item>
      <el-form-item label="获取时间" prop="hqTime">
        <el-date-picker value-format="YYYY-MM-DD" v-model="queryParams.hqTime" type="daterange" range-separator="-"
          start-placeholder="开始时间" end-placeholder="截止时间" :size="size" @change="hqTimeChange" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="postList"
      :default-sort="{ prop: 'panoramaAutoCreatParamPostDate', order: 'descending' }">
      <el-table-column type="index" width="55" align="center" label="序号" />
      <el-table-column label="任务Id" align="center" prop="taskId" width="200" />
      <el-table-column label="数据来源" align="center" prop="dataFrom">
        <template #default="scope">
          <dict-tag :options="data_sours" :value="scope.row.dataFrom" />
        </template>
      </el-table-column>
      <el-table-column label="上报时间" align="center" sortable prop="panoramaAutoCreatParamPostDate" />
      <el-table-column label="获取时间" align="center" sortable prop="panoramaAutoCreatResulGetDate" />
      <el-table-column label="是否已完成" align="center" prop="isComplete">
        <template #default="scope">
          <span>{{ scope.row.isComplete ? '是' : '否' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否告知发起方" align="center" prop="isCallBacked">
        <template #default="scope">
          <span>{{ scope.row.isCallBacked ? '是' : '否' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="View" @click="view(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize" @pagination="getList" />

    <!-- 日志详细 -->
    <el-dialog title="日志详细" v-model="open" width="800px" append-to-body>
      <el-form :model="form" label-width="140px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="任务id：">{{ form.taskId }}</el-form-item>
            <el-form-item label="数据来源：">{{ form.dataFrom }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="上报时间：">{{ form.panoramaAutoCreatParamPostDate }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="获取时间：">{{ form.panoramaAutoCreatResulGetDate }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否已完成：">{{ form.isComplete ? '是' : '否' }}</el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="是否告知发起方：">{{ form.isCallBacked ? '是' : '否' }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="参数json：">{{ form.panoramaAutoCreatParam }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="上报接口返回结果：">{{ form.panoramaAutoCreatParamPostResult }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="结果json：">{{ form.panoramaAutoCreatResul }}</el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="open = false">关 闭</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Post">
import { getPicLogs } from "@/api/720.js";

const { proxy } = getCurrentInstance();
const { sys_normal_disable, data_sours } = proxy.useDict("sys_normal_disable", "data_sours");

const postList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("全景生成详情");
const CompleteOptions = ref([
  { label: '是', value: true },
  { label: '否', value: false },
]);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    postCode: undefined,
    postName: undefined,
    status: undefined
  },
});

const { queryParams, form } = toRefs(data);

/** 查询列表 */
function getList() {
  loading.value = true;
  getPicLogs(queryParams.value).then(response => {
    postList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}
/** 表单重置 */
function reset() {
  form.value = {};
  proxy.resetForm("postRef");
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  queryParams.value = {}
  proxy.resetForm("queryRef");
  handleQuery();
}
/** 详情按钮操作 */
function view(row) {
  reset();
  form.value = row;
  open.value = true;
}

function sbTimeChange(value) {
  queryParams.value.panoramaAutoCreatParamPostDateBegin = value[0];
  queryParams.value.panoramaAutoCreatParamPostDateEnd = value[1];
  getList();
}


function hqTimeChange(value) {
  queryParams.value.panoramaAutoCreatResulGetDateBegin = value[0];
  queryParams.value.panoramaAutoCreatResulGetDateEnd = value[1];
  getList();
}
getList();
</script>

<style lang="scss" scoped>
::v-deep .el-form-item__content {
  white-space: pre-wrap;
  overflow-y: auto;
}
</style>
